<?
class LinkBO extends BusinessObject{

  /* private function using in constructors*/ 
  function setAttributes(){
    $this->fields   = array(
    'id'          =>   'linkID',
    'category'    =>   'linkCategory',   
    'url'         =>   'linkURL',
    'name'        =>   'linkName',
    'description' =>   'linkDescription',
    'email'       =>   'linkEmail',
    'page'        =>   'linkPage',
    'rate'        =>   'linkRate',
    'check'       =>   'linkCheck',
    'checkDate'   =>   'linkCheckDate',
    'add'         =>   'linkAdd',
    'checked'     =>   'linkChecked',
    'disabled'    =>   'linkDisabled');
    BusinessObject::setAttributes();
  }

  /* constructor */
  function LinkBO(){
    /** super(tableName) */
    BusinessObject::BusinessObject('links');
    $this->setAttributes();
  }

  function checkLink() {
		$this->http=&new Http();
		$this->cookie_file=tempnam('/tmp','');
		$this->stored_in=tempnam('/tmp','');
    $this->http->GET($this->page,$this->cookie_file,$this->stored_in);
    $fc=file_get_contents($this->stored_in);
//    echo(nl2br(htmlspecialchars($fc)));
    $l = &new LinkBO();
    if (preg_match("@<a[^>]+href=[\"']?".preg_quote(HTTP_OUR_SITE,'@')."[\"']?[^>]*>.*?</a>@si",$fc)>0) {
    //  found
//    echo('found');
      $l->checked=1;
    } else {
    //  not found
//    echo('not found');
      $l->checked=0;
    }
    $l->Update($this->tableName.'.'.$this->fields['id'].'='.$this->id);
    @unlink($this->cookie_file);
    @unlink($this->stored_in);
  }
}
?>